package studio.raptor.hub.common.util;

import java.io.Closeable;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author jack
 * @since 1.0
 */
public class JdbcUtils {

  private static final Logger log = LoggerFactory.getLogger(JdbcUtils.class);


  public static void close(Connection x) {
    if (x == null) {
      return;
    }
    try {
      x.close();
    }
    catch (Exception e) {
      log.debug("close connection error", e);
    }
  }


  public static void close(Statement x) {
    if (x == null) {
      return;
    }
    try {
      x.close();
    }
    catch (Exception e) {
      log.debug("close statement error", e);
    }
  }


  public static void close(ResultSet x) {
    if (x == null) {
      return;
    }
    try {
      x.close();
    }
    catch (Exception e) {
      log.debug("close result set error", e);
    }
  }


  public static void close(Closeable x) {
    if (x == null) {
      return;
    }

    try {
      x.close();
    }
    catch (Exception e) {
      log.debug("close error", e);
    }
  }

}
